<!--测评_评价等次信息表-->
<template>
  <el-dialog title="复用评价等次" :close-on-click-modal="false" :visible.sync="visible" width="800px">
    <el-container>
      <el-main style="max-height:60vh">
        <el-form :model="dataFormNew" ref="dataFormNew" @keyup.enter.native="dataFormSubmit()" label-width="140px">
          <el-row>
            <el-form-item label="等次名称" prop="djName" :rules="[
              { required: true, message: '等次名称不能为空', trigger: 'blur' },
              { min:1, max:100, message: '长度在 1 到 100 个字符', trigger: 'blur' }]">
              <el-input v-model="dataFormNew.djName" placeholder="等次名称" style='width:90%;'></el-input>
            </el-form-item>
            <el-form-item label="应用范围" prop="yyFw" :rules="[{ required: true, message: '应用范围不能为空', trigger: 'blur' }]">
              <el-select v-model="dataFormNew.yyFw" style='width:90%;'>
                <el-option v-for="(item,index) in ['个性','通用']" :key="index" :label="item" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
          </el-row>
        </el-form>
      </el-main>
    </el-container>
    <span slot="footer" class="dialog-footer">

      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button type="primary" plain @click="visible = false">取消</el-button>
    </span>

  </el-dialog>
</template>

<script>
import { getObj } from '@/api/ceping/cepingdjxxb'
import { postCoybDjmx } from '@/api/ceping/cepingdjxxb'

export default {
  data() {
    return {
      visible: false,
      canSubmit: false,
      dataFormNew: {
        djName: '',
        yyFw: ''
      },
      id: 0
    }
  },
  methods: {
    init(id) {
      this.id = id;
      this.visible = true;
      this.canSubmit = true;
      this.$nextTick(() => {
        this.$refs['dataFormNew'].resetFields();
        if (id) {
          getObj(id).then(response => {
            this.dataFormNew = response.data.data
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataFormNew'].validate((valid) => {
        if (valid) {
          this.canSubmit = false;

          postCoybDjmx(this.id, this.dataFormNew.djName, this.dataFormNew.yyFw).then(data => {
            this.$notify.closeAll();
            this.$notify.success('复用成功');
            this.visible = false;
            this.$emit('refreshDataList');
          }).catch(() => {
            this.canSubmit = true;
            this.$notify.closeAll();
            this.$notify.error("复用失败");
          });
        }
      })
    }
  }
}
</script>
<style scoped>
</style>
